/**
 * 
 */
package com.androspell.comicviewer.extractor;

import java.io.File;

import com.androspell.comicviewer.browser.ComicBean;
import com.androspell.comicviewer.browser.ScanPreference;

import android.content.Context;
import android.util.Log;

/**
 * It will check if the comic book is already extracted<br>
 * if it is then it will return path of extracted content <br>
 * else it will start extracting and return path.
 * 
 * @author swaroop @AndroSpell
 *
 * Date : 09-Oct-2011
 */
public class ExtractionManger {

	Context context;
	
	public ExtractionManger(Context context) {
		this.context = context;
	}
	
	private boolean isComicExtracted(String extractedPath){
		return new File(extractedPath).exists();
	}
	
	/**
	 * Constructs extraction path .. as given in preferences, 
	 * Check if already extracted and finally return extracted 
	 * path
	 * @param comicBean
	 * @return extractionPath
	 */
	public String startExtracting(ComicBean comicBean){
		String extractedPath = ExtractPreference.extractToLocation+comicBean.getBookTitle()+"/";
		if(isComicExtracted(extractedPath)){
			Log.i("ExtractionManger", "File Already Extracted");
			return extractedPath;
		}else{
			Log.i("ExtractionManger", "Extracting File");
			UnZip unZip = new UnZip();
			unZip.execute(comicBean);
		}
		return  extractedPath;
	}
	
	
}
